package net.jalbum.filters;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.JSlider;

import se.datadosen.jalbum.Msg;
import net.jalbum.filters.components.ExtendedSlider;

public class PixelateControl extends FilterControl {

	/**
	 *
	 */
	private static final long serialVersionUID = -7969686269619548580L;
	protected PixelateFilterPlugin pixelateFilterPlugin;
	protected ExtendedSlider pixelSizeSlider;
	protected JLabel textStrength;

	public PixelateControl(){}

	public PixelateControl(PixelateFilterPlugin pixelateFilterPlugin) {

		init(pixelateFilterPlugin);

		addPixelateControls();

	}

	protected void addPixelateControls() {
		textStrength = new JLabel(Msg.getString(this,"filters.pixelate.pixelSize"));
		pixelSizeSlider = new ExtendedSlider(JSlider.HORIZONTAL,1,10,5);
		pixelSizeSlider.getSlider().setMinorTickSpacing(1);
		pixelSizeSlider.getSlider().setPaintLabels(false);
		pixelSizeSlider.setSliderWidth(SLIDER_WIDTH);
		pixelSizeSlider.removeResetButton();
		pixelSizeSlider.addActionListener(this);

		this.add(textStrength);
		this.add("br",pixelSizeSlider);
	}

	protected void init(PixelateFilterPlugin pixelateFilterPlugin) {
		this.pixelateFilterPlugin = pixelateFilterPlugin;

		super.init(pixelateFilterPlugin);
	}

	public void actionPerformed(ActionEvent e) {
		super.actionPerformed(e);

		if (e.getSource()== pixelSizeSlider){
			pixelateFilterPlugin.setPixelSize(pixelSizeSlider.getValue());
			pixelateFilterPlugin.renderImage();
		}
	}
}
